import { MenuDataItem } from "@ant-design/pro-layout";
import ACCESS_ENUM from "@/access/accessEnum";
// 菜单列表
export const menus: MenuDataItem[] = [
  {
    path: '/',
    exact: true,
    redirect: '/mood'
  },
  {
    path: "/mood",
    name: "心情",
    background: "red",

  },
  {
    path: "/cook",
    name: "饭点",
  },
  {
    path: "/working",
    name: "待办",
  },
  {
    path: "/admin",
    name: "管理",
    access:ACCESS_ENUM.ADMIN,
    children: [
      {
        path: "/admin/user",
        name: "用户管理",
        access:ACCESS_ENUM.ADMIN
      },
      {
        path: "/admin/friend",
        name: "好友管理",
        access:ACCESS_ENUM.ADMIN
      },
    ]
  },
] as MenuDataItem[];

// 根据路径查找所有菜单
export const findAllMenuItemByPath = (path: string): MenuDataItem | null => {
  return findMenuItemByPath(menus, path);
};

// 根据路径查找菜单
export const findMenuItemByPath = (
    menus: MenuDataItem[],
    path: string,
): MenuDataItem | null => {
  for (const menu of menus) {
    if (menu.path === path) {
      return menu;
    }
    if (menu.children) {
      const matchedMenuItem = findMenuItemByPath(menu.children, path);
      if (matchedMenuItem) {
        return matchedMenuItem;
      }
    }
  }
  return null;
};

